package com.xjrsoft.module.customerTwo.EMP.electricity_cost_records_month.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xjrsoft.core.tool.utils.StringUtil;
import com.xjrsoft.module.customerTwo.EMP.electricity_cost_records_month.entity.TElectricityCostRecordsMonth;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.xjrsoft.core.tool.utils.CollectionUtil;
import java.util.ArrayList;
import com.xjrsoft.module.customerTwo.EMP.electricity_cost_records_month.dto.TElectricityCostRecordsMonthListDto;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.page.ConventPage;
import com.xjrsoft.common.page.PageOutput;
import java.util.List;
import java.util.Map;

import com.xjrsoft.module.customerTwo.EMP.electricity_cost_records_month.mapper.TElectricityCostRecordsMonthMapper;
import com.xjrsoft.module.customerTwo.EMP.electricity_cost_records_month.service.ITElectricityCostRecordsMonthService;
import com.xjrsoft.core.mp.base.BaseService;
import com.xjrsoft.core.tool.utils.Func;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 *  服务实现类
 *
 * @author dongxinhang
 * @since 2023-07-24
 */
@Service
@AllArgsConstructor
public class TElectricityCostRecordsMonthServiceImpl extends BaseService<TElectricityCostRecordsMonthMapper, TElectricityCostRecordsMonth> implements ITElectricityCostRecordsMonthService {


	@Override
	public IPage<TElectricityCostRecordsMonth> getPageList(TElectricityCostRecordsMonthListDto pageListDto) {
//		if(StringUtils.isNotBlank(pageListDto.getMonth())&&pageListDto.getMonth().startsWith("0")){
//			pageListDto.setMonth(pageListDto.getMonth().substring(1,2));
//		}
		Wrapper<TElectricityCostRecordsMonth> wrapper = Wrappers.<TElectricityCostRecordsMonth>query().lambda()
				.like(!StringUtil.isEmpty(pageListDto.getIdentify_name()), TElectricityCostRecordsMonth::getIdentifyName, pageListDto.getIdentify_name())
				.like(!StringUtil.isEmpty(pageListDto.getRoom_number()), TElectricityCostRecordsMonth::getRoomNumber, pageListDto.getRoom_number())
				.eq(!StringUtil.isEmpty(pageListDto.getYear()), TElectricityCostRecordsMonth::getYear, pageListDto.getYear())
				.eq(!StringUtil.isEmpty(pageListDto.getMonth()), TElectricityCostRecordsMonth::getMonth, pageListDto.getMonth());
		return this.page(ConventPage.getPage(pageListDto), wrapper);
	}

	@Override
	public int insertDataByDay(String start, String end) {
		return this.baseMapper.insertDataByDay(start,end);
	}

	@Override
	public List<Map<String,Object>> exportExcel(TElectricityCostRecordsMonthListDto dto) {
		List<Map<String,Object>> list = this.getBaseMapper().exportExcel(dto);
		for(Map one : list){
			Integer gender = (Integer) one.get("gender");
			if(null == gender){
				continue;
			}
			if(gender == 0||gender == 1){
				one.put("gender",gender == 0?"男":"女");
			}
		}
		return list;
	}

	@Override
	public IPage<Map<String, Object>> queryPage(Page page, TElectricityCostRecordsMonthListDto dto) {
		IPage<Map<String, Object>> pageList = this.getBaseMapper().queryPage(page,dto);
		if(CollectionUtil.isNotEmpty(pageList.getRecords())){
			for(Map one : pageList.getRecords()){
				Integer gender = (Integer) one.get("gender");
				if(null == gender){
					continue;
				}
				if(gender == 0||gender == 1){
					one.put("gender",gender == 0?"男":"女");
				}
			}
		}
		return pageList;
	}

}